<template>
  <div class="app-container">
    <el-dialog title="信息详情" :visible.sync="dialogVisible" width="65%" :before-close="handleClose">
      <div class="app-container">
        <el-descriptions v-loading="basicLoading" class="margin-top" title="患者入组基本信息" :column="2" border>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-price-tag"></i>
              门诊号
            </template>
            {{ basicInfo.patientNumber }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-place"></i>
              民族
            </template>
            {{ basicInfo.nation }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-postcard"></i>
              身份证号
            </template>
            {{ basicInfo.idNumber }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-user"></i>
              姓名
            </template>
            {{ basicInfo.name }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-s-custom"></i>
              职业
            </template>
            {{ basicInfo.profession }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-mobile-phone"></i>
              联系电话
            </template>
            {{ basicInfo.phoneNumber }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-paperclip"></i>
              婚姻
            </template>
            <dict-tag :options="dict.type.patient_info_marriage" :value="basicInfo.marriage" />
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-data-line"></i>
              体质指数[BMI]
            </template>
            {{ basicInfo.patientBmi }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-phone-outline"></i>
              紧急联系人
            </template>
            {{ basicInfo.emergencyContactNumber }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">年龄</template>
            {{ basicInfo.age }} 
            <el-tag size="small">岁</el-tag>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">身高</template>
            {{ basicInfo.height }} 
            <el-tag size="small">cm</el-tag>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">体重</template>
            {{ basicInfo.weight }}
            <el-tag size="small">kg</el-tag>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">烟、酒摄入史</template>
            <el-tag size="small" v-if="basicInfo.ingestHistory == null">无</el-tag>
            <span v-else>{{basicInfo.ingestHistory}} </span>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">运动频率</template>
            <el-tag size="small" v-if="basicInfo.exercise == null">无</el-tag>
            <span v-else>{{basicInfo.exercise}} </span>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">发病节气</template>
            <el-tag
              v-for="(item, index) in patientTerm"
              :key="index"
              size="small"
              style="margin-right:5px;"
            >{{item}}</el-tag>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">现居住地</template>
            {{ basicInfo.presentAddress }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">性别</template>
            <dict-tag :options="dict.type.sys_user_sex" :value="basicInfo.sex" />
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">病史可靠程度</template>
            <el-tag size="small" type="success" v-if="basicInfo.patientHistoryReliable === 1">可靠</el-tag>
            <el-tag size="small" type="warning" v-else-if="basicInfo.patientHistoryReliable === 0">不可靠</el-tag>
            <el-tag size="small" v-else>/</el-tag>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">就诊时间</template>
            {{ basicInfo.clinicTime }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">出生地</template>
            {{ basicInfo.birthAddress }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">记录时间</template>
            {{ basicInfo.createTime }}
          </el-descriptions-item>
        </el-descriptions>

        <div class="text-item">
          <span class="text-name">疾病信息添加轮次：</span>
          <span>
            <el-select @change="countChange" size="small" v-model="addCountId" placeholder="疾病信息添加轮次">
              <el-option
                v-for="item in countList"
                :label="item.name"
                :key="item.id"
                :value="item.id"
              ></el-option>
            </el-select>
          </span>
        </div>

        <!-- 患者疾病信息 -->
        <transition name="el-zoom-in-top">
          <div v-loading="diseaseLoading" class="disease-info" v-if="diseaseInfo"> 
          <el-descriptions  class="margin-top" title="患者疾病信息" :column="2" border>
            <el-descriptions-item>
              <template slot="label">体温</template>
              {{ diseaseInfo.temperature }} 
              <el-tag size="small">℃</el-tag>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">呼吸</template>
              {{ diseaseInfo.breath }} 
              <el-tag size="small">次/分</el-tag>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">血压</template>
              {{ diseaseInfo.bloodPressure }}
              <el-tag size="small">mmHg</el-tag>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">脉搏</template>
              {{ diseaseInfo.pulse }}
              <el-tag size="small">次/分</el-tag>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">KOA疾病分级</template>
              {{ koaGrade }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">是否首次治疗</template>
              <el-tag size="small" type="success" v-if="diseaseInfo.isFirstTreatment === 1">是</el-tag>
              <el-tag size="small" type="warning" v-else-if="diseaseInfo.isFirstTreatment === 0">否</el-tag>
              <el-tag size="small" v-else>/</el-tag>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">过敏史</template>
              <span v-if="diseaseInfo.allergyHistory == null">
                <el-tag size="small" type="warning">无</el-tag>
              </span>
              <span v-else>{{diseaseInfo.allergyHistory}}</span>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">K-L分期</template>
              {{ getKlStage()}}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">KOA描述</template>
              {{ koaDescribe }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">中医诊断及证型</template>
              <span v-if="treatmentInfo.diagnoseResult == null">
                <el-tag size="small" type="warning">无</el-tag>
              </span>
              <span v-else>{{treatmentInfo.diagnoseResult}}</span>
            </el-descriptions-item>
          </el-descriptions>
          <div class="previous-history" v-if="diseaseInfo.previousHistoryId != null">
            <h3 style="color: #1cbbb4;">既往史</h3>
            <el-descriptions class="margin-top" :column="3" border>
              <el-descriptions-item>  
                <template slot="label">疾病名称</template>
                {{ diseaseInfo.treatmentMap.previousHistory.diseaseName }}
              </el-descriptions-item>
              <el-descriptions-item>  
                <template slot="label">经历时间</template>
                {{ diseaseInfo.treatmentMap.previousHistory.startTime }} 至 {{ diseaseInfo.treatmentMap.previousHistory.endTime }}
              </el-descriptions-item>
              <el-descriptions-item>  
                <template slot="label">是否继续</template>
                <span v-if="diseaseInfo.treatmentMap.previousHistory.isContinue === 1">是</span>
                <span v-else-if="diseaseInfo.treatmentMap.previousHistory.isContinue === 0">否</span>
                <span v-else>/</span>
              </el-descriptions-item>
            </el-descriptions>
          </div>
          <!-- KOA治疗史（药物治疗） -->
          <div class="koa-drug-history" v-if="diseaseInfo.koaDrugHistoryId != null">
            <h3 style="color: #1cbbb4;">KOA治疗史（药物治疗）</h3>
            <el-descriptions class="margin-top" :column="2" border>
              <el-descriptions-item>  
                <template slot="label">药物名称</template>
                {{ diseaseInfo.treatmentMap.koaDrugHistory.drugName }}
              </el-descriptions-item>
              <el-descriptions-item>  
                <template slot="label">药物分类</template>
                {{ diseaseInfo.treatmentMap.koaDrugHistory.drugType }}
              </el-descriptions-item>
              <el-descriptions-item>  
                <template slot="label">药物用法</template>
                {{ diseaseInfo.treatmentMap.koaDrugHistory.drugUsage }}
              </el-descriptions-item>
              <el-descriptions-item>  
                <template slot="label">使用日期</template>
                {{ diseaseInfo.treatmentMap.koaDrugHistory.startTime }} 至 {{ diseaseInfo.treatmentMap.koaDrugHistory.endTime }}
              </el-descriptions-item>
              <el-descriptions-item>  
                <template slot="label">是否继续</template>
                <span v-if="diseaseInfo.treatmentMap.koaDrugHistory.isContinue === 1">是</span>
                <span v-else-if="diseaseInfo.treatmentMap.koaDrugHistory.isContinue === 0">否</span>
                <span v-else>/</span>
              </el-descriptions-item>
            </el-descriptions>
          </div>
          <!-- KOA治疗史（非药物治疗） -->
          <div class="koa-no-drug-history" v-if="diseaseInfo.koaNonDrugHistoryId != null">
            <h3 style="color: #1cbbb4;">KOA治疗史（非药物治疗）</h3>
            <el-descriptions class="margin-top" :column="2" border>
              <el-descriptions-item>  
                <template slot="label">治疗方法</template>
                {{ diseaseInfo.treatmentMap.koaNonDrugHistory.treatmentUsage }}
              </el-descriptions-item>
              <el-descriptions-item>  
                <template slot="label">治疗频次</template>
                {{ diseaseInfo.treatmentMap.koaNonDrugHistory.treatmentFrequency }}
              </el-descriptions-item>
              <el-descriptions-item>  
                <template slot="label">治疗日期</template>
                {{ diseaseInfo.treatmentMap.koaNonDrugHistory.startTime }} 至 {{ diseaseInfo.treatmentMap.koaNonDrugHistory.endTime }}
              </el-descriptions-item>
              <el-descriptions-item>  
                <template slot="label">是否继续</template>
                <span v-if="diseaseInfo.treatmentMap.koaNonDrugHistory.isContinue === 1">是</span>
                <span v-else-if="diseaseInfo.treatmentMap.koaNonDrugHistory.isContinue === 0">否</span>
                <span v-else>/</span>
              </el-descriptions-item>
            </el-descriptions>
          </div>
           <!-- KOA治疗史（手术治疗） -->
           <div class="koa-operation-history" v-if="diseaseInfo.koaOperationHistoryId != null">
            <h3 style="color: #1cbbb4;">KOA治疗史（手术治疗）</h3>
            <el-descriptions class="margin-top" :column="3" border>
              <el-descriptions-item>  
                <template slot="label">手术名称</template>
                {{ diseaseInfo.treatmentMap.koaOperationHistory.operationName }}
              </el-descriptions-item>
              <el-descriptions-item>  
                <template slot="label">治疗单位</template>
                {{ diseaseInfo.treatmentMap.koaOperationHistory.treatmentUnit }}
              </el-descriptions-item>
              <el-descriptions-item>  
                <template slot="label">治疗日期</template>
                {{ diseaseInfo.treatmentMap.koaOperationHistory.startTime }} 至 {{ diseaseInfo.treatmentMap.koaOperationHistory.endTime }}
              </el-descriptions-item>
            </el-descriptions>
           </div>
           <!-- 本院治疗（药物治疗） -->
           <div class="drug-treatment" v-if="treatmentInfo.drugTreatmentId != null">
              <h3 style="color: #1cbbb4;">本院治疗（药物治疗）</h3>
              <el-descriptions class="margin-top" :column="2" border>
                <el-descriptions-item>  
                <template slot="label">药物名称</template>
                {{ treatmentInfo.treatmentMap.drugTreatment.drugName }}
              </el-descriptions-item>
                <el-descriptions-item>  
                <template slot="label">药物分类</template>
                {{ treatmentInfo.treatmentMap.drugTreatment.drugType }}
              </el-descriptions-item>
                <el-descriptions-item>  
                <template slot="label">药物用法</template>
                {{ treatmentInfo.treatmentMap.drugTreatment.drugUsage }}
              </el-descriptions-item>
              <el-descriptions-item>  
                <template slot="label">使用日期</template>
                {{ treatmentInfo.treatmentMap.drugTreatment.startTime }} 至 {{ treatmentInfo.treatmentMap.drugTreatment.endTime }}
              </el-descriptions-item>
              </el-descriptions>
           </div>

           <!-- 本院治疗（非药物治疗） -->
           <div class="no-drug-treatment" v-if="treatmentInfo.nonDrugTreatmentId != null">
              <h3 style="color: #1cbbb4;">本院治疗（非药物治疗）</h3>
              <el-descriptions class="margin-top" :column="3" border>
                <el-descriptions-item>  
                <template slot="label">治疗方法</template>
                {{ treatmentInfo.treatmentMap.nonDrugTreatment.treatmentUsage }}
              </el-descriptions-item>
                <el-descriptions-item>  
                <template slot="label">治疗频次</template>
                {{ treatmentInfo.treatmentMap.nonDrugTreatment.treatmentFrequency }}
              </el-descriptions-item>
                <el-descriptions-item>  
                <template slot="label">治疗日期</template>
                {{ treatmentInfo.treatmentMap.nonDrugTreatment.startTime }} 至 {{ treatmentInfo.treatmentMap.nonDrugTreatment.endTime }}
              </el-descriptions-item>
              </el-descriptions>
          </div>

            <!-- 本院治疗（手术治疗） -->
            <div class="operation-treatment" v-if="treatmentInfo.operationTreatmentId != null">
              <h3 style="color: #1cbbb4;">本院治疗（手术治疗）</h3>
              <el-descriptions class="margin-top" :column="3" border>
                <el-descriptions-item>  
                <template slot="label">手术名称</template>
                {{ treatmentInfo.treatmentMap.operationTreatment.operationName }}
              </el-descriptions-item>
                <el-descriptions-item>  
                <template slot="label">治疗单位</template>
                {{ treatmentInfo.treatmentMap.operationTreatment.treatmentUnit }}
              </el-descriptions-item>
                <el-descriptions-item>  
                <template slot="label">治疗日期</template>
                {{ treatmentInfo.treatmentMap.operationTreatment.startTime }} 至 {{ treatmentInfo.treatmentMap.operationTreatment.endTime }}
              </el-descriptions-item>
              </el-descriptions>
          </div>
        </div>
        </transition>
        </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleClose">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { detailBasicInfo } from "@/api/gonitis/basicInfo";
import { diseaseDetail } from "@/api/gonitis/diseaseInfo";
export default {
  dicts: ["sys_user_sex", "patient_info_marriage"],
  props: {},
  data() {
    return {
      diseaseLoading: false,
      basicLoading: false,
      koaGrade: null,
      koaDescribe: null,
      countItemId: null,
      addCountId: null,
      patientTerm: [],
      basicInfo: {patientNumber: null},
      diseaseInfo: undefined,
      treatmentInfo: undefined,
      countList: [],
      dialogVisible: false,
      previousHistory: {},
    };
  },
  //方法集合
  methods: {
    /** 初始化 */
    init(basicId) {
      this.dialogVisible = true;
      this.basicLoading = true;
      detailBasicInfo(basicId).then(response => {
        this.$nextTick(() => {
          this.basicInfo = response.data.basicInfo;
          this.countList = response.data.countList;
          if (this.basicInfo.patientTerm != null) {
            this.patientTerm = this.basicInfo.patientTerm.split("/");
          }
        });
        this.basicLoading = false;
      });
    },
    /** 获取klStage分期 */
    getKlStage(){
      switch(this.treatmentInfo.klStage){
        case 0:
          return '[ 左、L ]';
        case 1:
          return '[ 右、R ]';
        default:
          return "/";
      } 
    },
    /** 疾病信息加入记录改变 */
    countChange(diseaseId) {
      // 发送请求获取疾病信息
      this.diseaseInfo = null;
      this.treatmentInfo = null;
      this.koaGrade = null;
      this.koaDescribe = null;
      this.diseaseLoading = true;
      diseaseDetail(diseaseId).then(response => {
        this.$nextTick(() => {
          this.diseaseInfo = response.data.diseaseInfo;
          this.treatmentInfo = response.data.treatmentInfo;
          this.koaGrade = response.data.koaGrade;
          this.koaDescribe = response.data.koaDescribe;
        });
        this.diseaseLoading = false;
      });
    },
    handleClose() {
      this.dialogVisible = false;
      this.$parent.detailVisible = false;
    },
  }
};
</script>
<style scoped>
.text-item {
  margin-top: 10px;
  font-size: 14px;
  margin-bottom: 5px;
}
.text-name {
  font-weight: bold;
  color: rgb(124, 120, 120);
}
</style>